﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mscook.core.domain;
using NHibernate.Linq;

namespace mscook.core.repositories
{
    public class RelativeLinkRepository:Repository<RelativeLink>, mscook.core.repositories.IRelativeLinkRepository
    {

        public RelativeLink GetByResourceId(string resourceId)
        {
            var query = (from x in this.Session.Query<RelativeLink>() select x)
             .Where(o => o.IsDelete == false
                 && o.ResourceId == resourceId).OrderByDescending(o => o.EntityIndex);
            return query.SingleOrDefault();
        }


        public IList<RelativeLink> GetByResourceIds(IList<string> resourceIds)
        {
            var query = (from x in this.Session.Query<RelativeLink>() select x)
             .Where(o => o.IsDelete == false
                 && resourceIds.Contains(o.ResourceId)).OrderByDescending(o => o.EntityIndex);
            return query.ToList();
        }
    }
}
